﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using MobileClient.PublicFunctionClass;
using MobileClient.MobileClientBackgroundRef;

namespace MobileClient
{
    public partial class ToDoTask : BasePageClass.BasePage
    {
        private Ultimus_MobileServices services = new Ultimus_MobileServices();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BingMyTask();
            }
        }

        private void BingMyTask()
        {
            try
            {
                UserInfo uUserInfo = Session["UserInfo"] as UserInfo;
                List<Tasks> info = new List<Tasks>();
                info.AddRange(services.GetMyTaskListOfUltimusEik(uUserInfo.UserAccount));
                //根据条件过滤
                List<Tasks> newinfo = info.FindAll(delegate(Tasks t)
                {
                    if (!String.IsNullOrEmpty(txtProcessName.Text.Trim()))
                    {
                        return t.ProcessName.Contains(txtProcessName.Text.Trim());
                    }
                    if (!String.IsNullOrEmpty(txtIncident.Text.Trim()))
                    {
                        return t.Incident.ToString().Contains(txtIncident.Text.Trim());
                    }
                    if (!String.IsNullOrEmpty(txtStepName.Text.Trim()))
                    {
                        return t.StepName.Contains(txtStepName.Text.Trim());
                    }
                    if (!String.IsNullOrEmpty(txtSummary.Text.Trim()))
                    {
                        return t.Summary.Contains(txtSummary.Text.Trim());
                    }
                    return true;
                });
                List<Tasks> list = new List<Tasks>();
                int index = AspNetPager1.CurrentPageIndex;
                int pageIndex = AspNetPager1.CurrentPageIndex - 1;
                int pageSize = AspNetPager1.PageSize;
                for (int i = 0; i < newinfo.Count; i++)
                {
                    if (i >= pageIndex * pageSize && i < index * pageSize)
                    {
                        list.Add(newinfo[i]);
                    }
                }
                Repeater1.DataSource = list.ToArray();
                Repeater1.DataBind();
                AspNetPager1.RecordCount = info.Count;
            }
            catch (Exception ex)
            {
                PublicClass.ShowMessage(this.Page, Resources.Resource.ToDoTask_ErrorMessage1);
                PublicClass.WriteLogOfTxt(ex.Message);
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BingMyTask();
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            BingMyTask();

        }

    }
}